package edu.xidian.sei

import scala.io.Source
import scala.collection.mutable.ArrayBuffer
import scala.util.Random
import java.text.DecimalFormat

import scala.collection.mutable.HashMap
import java.io.File

import scala.collection.mutable

object Test {
  //  def main(args: Array[String]): Unit = {
  //    val file = Source.fromFile(".\\label.txt")
  //    val format = new DecimalFormat("0.0000")
  //    val classMap = new HashMap[String,Int]
  //    val writer1 = new java.io.PrintWriter("2dpoint.txt")
  //    val writer2 = new java.io.PrintWriter("2dpointwithlabel.txt")
  //    for (line <- file.getLines) {
  //      val array = line.split(",").take(2).map(x => format.format(x.toDouble))
  //      writer2.println(array.mkString(",") + "," + line.split(",").takeRight(1)(0))
  //      writer1.println(array.mkString(","))
  //    }
  //    writer1.close()
  //    writer2.close()
  //  }

  //  def main(args: Array[String]): Unit = {
  //    val file = Source.fromFile(".\\label.txt")
  //    val format = new DecimalFormat("0.0000")
  //    val classMap = new HashMap[String, Int]
  //    val writer = new java.io.PrintWriter("2dpoint.txt")
  //    var num = 1
  //    for (line <- file.getLines) {
  //      val array = line.split("=>")
  //      val clusterName = array(1)
  //      if (classMap.contains(clusterName)) {
  //        writer.println(array(0) + "=>" + classMap.get(clusterName).get)
  //      } else {
  //        num += 1
  //        classMap.put(clusterName, num)
  //        writer.println(array(0) + "=>" + classMap.get(clusterName).get)
  //      }
  //
  //    }
  //    writer.close()
  //
  //  }
  def main(args: Array[String]): Unit = {
    //    findFiles(".\\", "newoutput")
    //val filereader = Source.fromFile("20KDDCUP99_normal_unlabel_no.txt").getLines()
    val map = Map("1" -> 1, "2" -> 2, "3" -> 3)
    val set = mutable.HashSet.empty[String] ++ map.keySet
    set.foreach(println)
    println("unlabel")
  }

  def findFiles(path: String, name: String): ArrayBuffer[String] = {
    val fileNmesList = new ArrayBuffer[String]()
    val file = new File(path);
    val files = file.listFiles()
    val fileNames = file.list()
    files.foreach { f =>
      if (f.isFile() && f.getName().startsWith(name)) {
        val file = Source.fromFile(f.getName)
        val classMap = new HashMap[String, Int]
        val writer = new java.io.PrintWriter("new" + f.getName)
        var num = 0
        for (line <- file.getLines) {
          //          val array = line.split("=>")
          //          val clusterName = array(1)
          //          if (classMap.contains(clusterName)) {
          //            writer.println(array(0) + "=>" + classMap.get(clusterName).get)
          //          } else {
          //            num += 1
          //            classMap.put(clusterName, num)
          //            writer.println(array(0) + "=>" + classMap.get(clusterName).get)
          //          }
          val array = line.split("=>")
          writer.println(array(0) + "," + array(1))

        }
        writer.close()
      }
    }
    fileNmesList
  }

}